<%--
  Created by IntelliJ IDEA.
  User: wj
  Date: 2018-11-08
  Time: 10:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>

        //得到查询的参数
        function queryParams (params) {

        };

        $(function () {
            $("#yuangongtb").bootstrapTable({
                url:'${pageContext.request.contextPath}/yuangong/querySearch',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        yname:$("#yname").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'yid',
                        title:'编号'
                    },
                    {
                        field:'yname',
                        title:'姓名'
                    },
                    {
                        field:'yzhuwu',
                        title:'职务'
                    },

                    {
                        field:'yphone',
                        title:'电话'
                    },
                    {
                        field:'yaddress',
                        title:'地址'
                    },
                    {
                        field:'quanxian',
                        title:'权限'
                    },

                    {
                        title:'操作',
                        formatter:function(value,row,index){
                            return "<button onclick='javascript:del("+row.yid+")'>删除</button>"+
                                "<button onclick='javascript:ud("+row.yid+")'>修改</button>"
                        }
                    },
                ]
            }) ;
        }) ;

        function searcha() {
            //返回表格的 Options。
            var opts = $("#yuangongtb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var yname = $("#yname").val() ;
            $.post("${pageContext.request.contextPath}/yuangong/querySearch",{'yname':yname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#yuangongtb").bootstrapTable('load',data) ;
            })
        }

        function add(){
            $("#Div3").modal('show');
        }

        function doadd(){
            var yname=$("[name=yname]").val();
            var yzhuwu=$("[name=yzhuwu]").val();
            var yphone=$("[name=yphone]").val();
            var yaddress=$("[name=yaddress]").val();
            var quanxian=$("[name=quanxian]").val();
            $.post('${pageContext.request.contextPath}/yuangong/inst',{yid:yid,yname:yname,yzhuwu:yzhuwu,yphone:yphone,yaddress:yaddress,quanxian:quanxian},function(data){
                if(data!= null){
                    searcha();
                    $("#Div3").modal('hide');
                }else{
                    alert("增加失败！");
                }
            })
        }


        var yid;

        function del(kids){
            yid=kids;
            $("#sc").modal('show');

        }

        function dodelete(){
            $.post('${pageContext.request.contextPath}/yuangong/shanchu',{yid:yid},function(data){
                if(data>0){
                    $.post("${pageContext.request.contextPath}/yuangong/querySearch",{'yname':yname,'limit':limit,'offset':offset},function (data) {
                        //重新绑定表格数据
                        $("#yuangongtb").bootstrapTable('load',data) ;
                        $("#sc").modal('hide');
                    })
                }
            })
        }

        var yid=0;
        function ud(id){
            yid=id;
            $("#Div4").modal('show');
            //发送post请求
            $.post('${pageContext.request.contextPath}/yuangong/queryById',{yid:yid},function(data){
                //给表单赋值
                $("[name=yname]").val(data.yname);
                $("[name=yzhuwu]").val(data.yzhuwu);
                $("[name=yphone]").val(data.yphone);
                $("[name=yaddress]").val(data.yaddress);
                $("[name=quanxian]").val(data.quanxian);
            })


        };

        function doupd(){
            var yname=$("[name=yname]").val();
            var yzhuwu=$("[name=yzhuwu]").val();
            var yphone=$("[name=yphone]").val();
            var yaddress=$("[name=yaddress]").val();
            var quanxian=$("[name=quanxian]").val();
            $.post('${pageContext.request.contextPath}/yuangong/xg',{yid:yid,yname:yname,yzhuwu:yzhuwu,yphone:yphone,yaddress:yaddress,quanxian:quanxian},function(data){
                if(data!= null){
                    searcha();
                    $("#Div4").modal('hide');
                }else{
                    alert("修改失败！");
                }
            })

        }

    </script>


</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">员工列表</h3>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-6">
                <button onclick="add()" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;增加</button>
            </div>
            <div class="col-sm-6">
                <form  class="form-inline pull-right">
                    <input id="yname" type="text" class="form-control">
                    <button class="btn btn-primary" onclick="searcha()" type="button"><span class="glyphicon glyphicon-search"></span>&nbsp;&nbsp;搜索</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table id="yuangongtb"></table>
            </div>
        </div>

    </div>
</div>

<!---删除模态框-->
<div class="modal fade" id="sc">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12" id="addrole" style="height: 100px">
                        <p>确认删除客户信息吗？</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"onclick="dodelete()">删除</button>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="Div3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">增加员工信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" >
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yname" class="form-control" id="title1" placeholder="请输入供应商名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工职务:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yzhuwu" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商联系人">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工电话:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yphone" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商电话">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工地址:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yaddress"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商地址">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工权限:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="quanxian"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入员工权限">
                        </div>
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary"  onclick="doadd()">增加</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="Div4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">修改员工信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" >
                    <div class="form-group">
                        <label for="titile" class="col-sm-2 control-label">员工名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yname" class="form-control" id="title" placeholder="请输入供应商名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工职务:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yzhuwu" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商联系人">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工电话:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yphone" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商电话">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工地址:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="yaddress"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商地址">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">员工权限:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="quanxian"  class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入供应商备注">
                        </div>
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary"  onclick="doupd()">修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


</body>
</html>
